//
//  NewActibityTableViewCell.m
//  UI_APP_Project_Bean
//
//  Created by dllo on 16/6/25.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "NewActibityTableViewCell.h"
#import "ActivityModel.h"


@interface NewActibityTableViewCell ()

@property(nonatomic, retain)UIImageView *backBig;
@property(nonatomic, retain)UIImageView *whiteBack;
@property(nonatomic, retain)UILabel *themeLabel;
@property(nonatomic, retain)UILabel *timeLabel;
@property(nonatomic, retain)UILabel *addressLabel;
@property(nonatomic, retain)UILabel *typeLabel;
@property(nonatomic, retain)UILabel *interesting;
@property(nonatomic, retain)UILabel *join;
@property(nonatomic, retain)UIImageView *rightImageView;
@property(nonatomic, retain)UIImageView *time;
@property(nonatomic, retain)UIImageView *adre;
@property(nonatomic, retain)UIImageView *typ;

@end



@implementation NewActibityTableViewCell

- (void)dealloc
{
    [_whiteBack release];
    [_backBig release];
    [_activityModel release];
    [_themeLabel release];
    [_timeLabel release];
    [_addressLabel release];
    [_typeLabel release];
    [_interesting release];
    [_join release];
    [_rightImageView release];
    [_time release];
    [_adre release];
    [_typ release];
    [super dealloc];

}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backBig = [[UIImageView alloc]init];
        [self.contentView addSubview: _backBig];
        [_backBig release];
        
        self.themeLabel = [[UILabel alloc]init];
        self.themeLabel.font = [UIFont systemFontOfSize:20];
        [_backBig addSubview:_themeLabel];
        [_themeLabel release];
        
        self.whiteBack = [[UIImageView alloc]init];
        [_backBig addSubview:_whiteBack];
        [_whiteBack release];
        
        self.time = [[UIImageView alloc]init];
        [_whiteBack addSubview:_time];
        [_time release];
        
        self.timeLabel = [[UILabel alloc]init];
        [_whiteBack addSubview:_timeLabel];
        [_timeLabel release];
        
        
        self.adre = [[UIImageView alloc]init];
        [_whiteBack addSubview:_adre];
        [_adre release];
        
        self.addressLabel = [[UILabel alloc]init];
        [_whiteBack addSubview:_addressLabel];
        [_addressLabel release];
        
        
        self.typ = [[UIImageView alloc]init];
        [_whiteBack addSubview:_typ];
        [_typ release];
        self.typeLabel = [[UILabel alloc]init];
        [_whiteBack addSubview:_typeLabel];
        [_typeLabel release];
        
        self.rightImageView = [[UIImageView alloc]init];
        [_whiteBack addSubview:_rightImageView];
        [_rightImageView release];
        
        self.interesting = [[UILabel alloc]init];
        self.interesting.textColor = [UIColor redColor];
        [_whiteBack addSubview:_interesting];
        [_interesting release];
        
        self.join = [[UILabel alloc]init];
        self.join.textColor = [UIColor redColor];
        [_whiteBack addSubview:_join];
        [_join release];
        
    }
    return self;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    
    self.backBig.frame = CGRectMake(10, 5, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 10);
    self.backBig.image = [UIImage imageNamed:@"bg_eventlistcell@2x"];
    
    self.themeLabel.frame = CGRectMake(5, 5, _backBig.frame.size.width, _backBig.frame.size.height / 5);
    
    self.whiteBack.frame = CGRectMake(2, _themeLabel.frame.size.height, _backBig.frame.size.width - 4, _backBig.frame.size.height * 0.8 - 5);
    self.whiteBack.image = [UIImage imageNamed:@"bg_share_large@2x"];
   
    self.time.frame = CGRectMake(9, 5, 22, 22);
    self.time.image = [UIImage imageNamed:@"icon_date.png"];
    self.adre.frame = CGRectMake(9, 25, 22, 22);
    self.adre.image = [UIImage imageNamed:@"icon_spot.png"];
    self.typ.frame = CGRectMake(9, 45, 22, 22);
    self.typ.image = [UIImage imageNamed:@"icon_catalog.png"];
    
    self.timeLabel.frame = CGRectMake(_time.frame.origin.x + _time.frame.size.width + 4, _time.frame.origin.y, _whiteBack.frame.size.width * 0.6, _time.frame.size.height);
    self.addressLabel.frame = CGRectMake(_timeLabel.frame.origin.x, _timeLabel.frame.size.height + _timeLabel.frame.origin.y, _timeLabel.frame.size.width, _timeLabel.frame.size.height);
    self.typeLabel.frame = CGRectMake(_addressLabel.frame.origin.x, _addressLabel.frame.origin.y + _addressLabel.frame.size.height, _addressLabel.frame.size.width, _addressLabel.frame.size.height);
    
    
    self.interesting.frame = CGRectMake(_typ.frame.origin.x, _typeLabel.frame.origin.y + _typeLabel.frame.size.height + 32, _whiteBack.frame.size.width * 0.3, 20);
    self.join.frame = CGRectMake(_interesting.frame.origin.x + _interesting.frame.size.width + 15 , _interesting.frame.origin.y, _interesting.frame.size.width, _interesting.frame.size.height);
    
    
    self.rightImageView.frame = CGRectMake(_time.frame.size.width + _timeLabel.frame.size.width + 7 , _time.frame.origin.y , _whiteBack.frame.size.width * 0.3, _whiteBack.frame.size.height - 10);
    
    
}

-(void)setActivityModel:(ActivityModel *)activityModel{
    
    if (_activityModel != activityModel) {
        [_activityModel release];
        _activityModel = [activityModel retain];
    }
    self.themeLabel.text = activityModel.title;
    
    NSString *beginTime = [NSString stringWithFormat:@"%@", [activityModel.begin_time substringWithRange:NSMakeRange(5, 11)]];
    NSString *engTime = [NSString stringWithFormat:@"%@", [activityModel.end_time substringWithRange:NSMakeRange(5, 11)]];
    self.timeLabel.text = [NSString stringWithFormat:@"%@--%@", beginTime, engTime];
    
    self.addressLabel.text = activityModel.address;
    self.typeLabel.text = [NSString stringWithFormat:@"类型: %@",  activityModel.category_name];
    
    // 富文本
    NSString*strOfinterest =[NSString stringWithFormat:@"感兴趣:  %ld", activityModel.wisher_count];
    NSMutableAttributedString *strOfinter = [[NSMutableAttributedString alloc]initWithString:strOfinterest];
    [strOfinter addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, 4)];
    self.interesting.attributedText = strOfinter;
    [strOfinter release];
    // 富文本
   NSString *join =[NSString stringWithFormat:@"参加: %ld", activityModel.participant_count];
    NSMutableAttributedString *joinText = [[NSMutableAttributedString alloc]initWithString:join];
    [joinText addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, 3)];
    self.join.attributedText = joinText;
    [joinText release];
    
    
    
    self.rightImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:activityModel.image_hlarge]]];
    
    
    
    
}

@end
